package top.healthylife.service.impl;/*
 *@Author GaoZeXi
 *@Created time 2020/4/4 23:58
 *@Description:
 * Step by Step  and Stand on,  You Are The Best Investment!!!
 */

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import top.healthylife.domain.CheckItem;
import top.healthylife.entity.PageResult;
import top.healthylife.entity.QueryPageBean;
import top.healthylife.mapper.CheckItemMapper;
import top.healthylife.service.CheckItemService;

import java.util.List;

@Service(interfaceClass =CheckItemService.class )
@Transactional
public class CheckItemServiceImpl implements CheckItemService {
    @Autowired
    private CheckItemMapper checkItemMapper;
    @Override
    public void add(CheckItem checkItem) {

        checkItemMapper.add(checkItem);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        int currentPage = queryPageBean.getCurrentPage();
        int pageSize =  queryPageBean.getPageSize();
        //开启分页
        PageHelper.startPage(currentPage,pageSize);
        String queryString  = queryPageBean.getQueryString();
        Page<CheckItem> page = checkItemMapper.selectByCondition(queryString);
        System.out.println("总记录=============="+page.getTotal());
        System.out.println("结果集=============="+page.getResult());
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void delete(Integer id) {
        //查询当前检查项是否和检查组关联
        long count =checkItemMapper.selectCountByCheckItemId(id);
        if (count>0){
            throw new RuntimeException("当前检查项被引用,不能删除");
        }
        checkItemMapper.delete(id);
    }

    @Override
    public CheckItem findById(Integer id) {
        return checkItemMapper.findById(id);
    }

    @Override
    public void update(CheckItem checkItem) {
        checkItemMapper.update(checkItem);
    }

    @Override
    public List<CheckItem> findAll() {
        return checkItemMapper.findAll();
    }
}
